package cn.ljlao.mall.product.goods.dataSource.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author liuzhen
 * @Description:
 * @date 2022/1/6 13:41
 */
public class DataSourceUtil {

	/**
	 * 测试数据源连接是否正常
	 * @param url url地址
	 * @param username 用户名
	 * @param password 密码
	 * @return
	 */
	public static boolean  testDatasource( String url, String username, String password,String driverName) {
		Connection connection =null;
		try {
			Class.forName(driverName);
			connection = DriverManager.getConnection(url, username, password);
			return true;
		} catch (Exception e) {
			return false;
		}finally {
			try {
				if (connection!=null){
					connection.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}


	}
}
